package com.sixth.service.Impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sixth.dao.KeyboardcolorDao;
import com.sixth.entity.Keyboardcolor;
import com.sixth.entity.Staff;
import com.sixth.service.KeyboardcolorService;
import com.sixth.util.CommonResult;
import com.sixth.util.TableLayUi;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @program: project01
 * @description:
 * @author: 老魏
 * @create: 2021-12-27 16:15
 **/
@Service("/keyboardcolorService")
public class KeyboardcolorServiceImpl implements KeyboardcolorService {
    @Autowired
    private KeyboardcolorDao keyboardcolorDao;

   public TableLayUi findAllKeyboardcolor(int page,int limit,Integer keyboardcolorid,String keyboardcolorname){
        PageHelper.startPage(page,limit);
        List<Keyboardcolor> list = keyboardcolorDao.selectAllKeyboard(keyboardcolorid,keyboardcolorname);
        PageInfo<Keyboardcolor> pageInfo = new PageInfo<Keyboardcolor>(list);
        //pageInfo.getTotal:获取的为表中总条数
        //pageInfo.getList():获取的为当前页的记录数据
        return new TableLayUi(0,"",pageInfo.getTotal(),pageInfo.getList());
    }

    public  CommonResult deleteKeyboardcorlor(Integer keyboardcolorid ){
        int row = keyboardcolorDao.deleteByPrimaryKey(keyboardcolorid);
        if (row>0){
            return new CommonResult(2000,"删除成功",null);
        }else {
            return new CommonResult(5000,"删除失败",null);
        }
    }

    public  CommonResult addKeyboardcorlor(String keyboardcolorname){
        int row = keyboardcolorDao.addKeyboard(keyboardcolorname);
        if (row>0){
            return new CommonResult(2000,"新增成功",null);
        }else {
            return new CommonResult(5000,"新增失败",null);
        }
    }

    public  CommonResult updateKeyboardcorlor(Keyboardcolor keyboardcolor) {
        int row = keyboardcolorDao.updateKeyboard(keyboardcolor);
        if (row>0){
            return new CommonResult(2000,"新增成功",null);
        }else {
            return new CommonResult(5000,"新增失败",null);
        }
    }
    public TableLayUi findboardCondition (int page, int limit,String keyboardcolorid , String keyboardcolorname){
        PageHelper.startPage(page,limit);
        List<Keyboardcolor> Keyboardcolors= keyboardcolorDao.selectboardCondition(keyboardcolorid,keyboardcolorname);
        PageInfo<Keyboardcolor> pageInfo= new PageInfo<Keyboardcolor>(Keyboardcolors);
        return new  TableLayUi(0,"",pageInfo.getTotal(),pageInfo.getList());
    }
}
